<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>novalContent</title>
    <link rel="stylesheet" href="../statics/css/bootstrap.min copy.css">
    <link rel="stylesheet" href="../statics/css/novalContent.css">
    <link rel="stylesheet" href="../statics/HTMLPage/page.css">
</head>

<body background="../statics/Photo/雪地.jpg" style="background-repeat: no-repeat;
background-size: 100% 100%;
background-attachment: fixed;
width:100%;">
    <div class="container">
        <div class="row">
            <div class="col-sm">
                <div id="left">
                    <div id="personalData">
                        <div class="card-header"
                            style="font-family: fantasy; font-size: 25px;margin-left: 28px; float: left;margin-bottom: 5px;border: solid 2px black;border-radius: 8px;">
                            Personal Data
                        </div>
                        <p style="font-family: fantasy;"></p>

                        <!-- 头像 -->
                        <img src="../statics/Photo/p.png" alt="" style="margin-left: 20px;margin-top: 0px;">
                        <p></p>
                        <!-- 昵称 -->
                        <p
                            style="font-family: fantasy;font-size: 20px;margin-left: 40px;border: solid 2px black;border-radius: 8px;width: 160px;text-align: center;color: #000;">
                            User:&nbsp;&nbsp;&nbsp;&nbsp;{{username}}</p>
                        <!-- 虚线 -->
                        <hr style="border:1px dashed #000" />

                        <p></p>
                        <li id="friends" style="border: solid 2px black;border-radius: 5px;display: inline;">加好友</li>
                        <li id="addNews" style="border: solid 2px black;border-radius: 5px;display: inline;">加关注</li>
                        <p></p>
                        <li id="sendPaper" style="border: solid 2px black;border-radius: 5px;display: inline;">发纸条</li>
                        <li id="writeTalk" style="border: solid 2px black;border-radius: 5px;display: inline;">写留言</li>
                        <p></p>

                        <hr style="border:1px dashed #000" /> &nbsp;&nbsp;

                        <span style="font-family:fantasy;">Level:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <span style="font-family: fantasy;font-size: larger ;">130</span><br>
                        <br> &nbsp;&nbsp;&nbsp;

                        <span style="font-family:fantasy;">P&nbsp;&nbsp;V:</span>
                        <span
                            style="font-family: fantasy;font-size: larger ;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4,546,231,742</span><br>
                        <br> &nbsp;

                        <span style="font-family:fantasy;">Attention:</span>
                        <span style="font-family: fantasy;font-size: larger ;">&nbsp;&nbsp;&nbsp;945,213</span><br>
                        <br> &nbsp;

                        <span style="font-family:fantasy;">Gold Icon:</span>
                        <span style="font-family:fantasy;">&nbsp;&nbsp;&nbsp;&nbsp;133,785</span><br>
                        <br> &nbsp;&nbsp;

                        <span style="font-family:fantasy;">Medal:</span>
                        <span style="font-family:fantasy;">&nbsp;&nbsp;&nbsp;&nbsp;</span>

                    </div>
                </div>
            </div>


            <div class="col-sm">
                <div class="card-header"
                    style="font-family: fantasy; font-size: 25px;;border: solid 2px black;border-radius: 8px;height: 60px;margin-top: 20px;">
                    Just Saying
                </div>
                <div style="width: 52rem;opacity: 0.7;">
                    <div class="card-header">
                        <div class="row">
                            <div class="col-sm-4 d-flex justify-content-start">
                                <button type="button" class="btn btn-secondary btn-sm" data-toggle="modal"
                                    data-target="#saysomething"
                                    style="font-family: fantasy;font-size: 20px;background-color:deepskyblue;">Post</button>
                            </div>
                            <div class="col-sm-4 d-flex justify-content-center">
                                <p style="font-family: fantasy;font-size: 14px;margin-top: 10px;">Welcome to your write
                                    life📕</p>
                            </div>
                            <div class="col-sm-4 d-flex justify-content-end"><button type="button"
                                    class="btn btn-secondary btn-sm" onclick="logout()"
                                    style="font-family: fantasy;font-size: 20px;background-color:deepskyblue;">Logout</button>
                            </div>
                        </div>
                    </div>

                </div>
                <br>
                <table width="500" style="height: 500px;" cellpadding="0" cellspacing="0" class="table2" align="center">
                    <!-- <div id="Content" style="height: 400px;width: 500px;"> -->
                    <!-- <div class="row" style="margin-top:5px;opacity: 0.7;"> -->

                    <!-- <div class="col-sm">
                            </div> -->
                    <tbody id="adminTbody">

                        <c:forEach items="${user }" var="user">
                            <div class="col-sm" id="saysayMsg" style="width: 48rem;">
                                {% for msg in msgs %}
                                <div class="card border-primary shadow" style="width: 600px;">
                                    <div class="card-header">
                                        <div class="row">
                                            <div class="col-sm-10" style="font-family: fantasy;font-size: 20px;">
                                                {{msg.content}}</div>
                                            <div class="col-sm-2"><button type="button" class="btn btn-secondary btn-sm"
                                                    data-toggle="modal" data-target="#comment"
                                                    onclick="msgCommit('{{msg.id}}')">Talk
                                                    Show</button>
                                            </div>
                                        </div>

                                    </div>
                                    <div class="card-body">
                                        <ul class="list-group list-group-flush" id="{{msg.id}}">
                                            {% for cmot in msg.comments %}
                                            <li class="list-group-item">
                                                <blockquote class="blockquote mb-0">
                                                    <p>{{cmot.content}}</p>
                                                    <footer class="blockquote-footer">
                                                        <cite title="Source Title">{{cmot.comUserName}}</cite>&nbsp;&nbsp;对
                                                        <cite title="Source Title">{{msg.msgUserName}}</cite>&nbsp;&nbsp;说
                                                    </footer>
                                                </blockquote>
                                            </li>
                                            {% endfor %}
                                        </ul>

                                    </div>
                                </div>

                                {% endfor %}
                        </c:forEach>
                    </tbody>
                    <div id="barcon" class="barcon">

                        <div id="barcon1" class="barcon1"></div>

                        <div id="barcon2" class="barcon2">

                            <ul>

                                <li><a href="###" id="firstPage">首页</a></li>

                                <li><a href="###" id="prePage">上一页</a></li>

                                <li><a href="###" id="nextPage">下一页</a></li>

                                <li><a href="###" id="lastPage">尾页</a></li>

                                <li><select id="jumpWhere">
                                                        </select></li>

                                <li><a href="###" id="jumpPage" οnclick="jumpPage()">跳转</a></li>
                            </ul>
                        </div>
                    </div>

                    <!-- </div> -->
                    <div class="col-sm">
                    </div>
                    <!-- </div> -->

            </div>
            </table>
        </div>
        <div class="col-sm">
        </div>

    </div>


    </div>

    <div class="modal fade" id="saysomething" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Post Talk</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <input type="text" class="form-control" aria-describedby="passwordHelpInline" name="msgSay"
                                id="msgSay">
                            </small>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">CANCLE</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="say()">POST</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="comment" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Talk Show</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <input type="text" class="form-control" aria-describedby="passwordHelpInline"
                                id="commentText">

                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancle</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="talkComment()">Talk
                        Show</button>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="../statics/js/jquery-3.6.0.min.js"></script>
<script src="../statics/js/bootstrap.min.js"></script>

<script>
    let currentMsgId = '';

    function logout() {
        $.ajax({
            url: "/logout",
            type: "POST",
            dataType: "json",
            success: function (res) {
                if (res.code === 200) {
                    window.location.href = '/login'
                }
            },
            error: function (msg) {
                console.log('网络错误！');
            }
        })
    }

    function say() {
        var getTime = new Date();
        var YY = getTime.getFullYear();
        var MM = getTime.getMonth() + 1;
        var DD = getTime.getDate();
        var hh = getTime.getHours();
        var mm = getTime.getMinutes();
        var ss = getTime.getSeconds();
        var day = getTime.getDay();
        let data = {
            msgSay: $('#msgSay').val()
        }
        $.ajax({
            url: "/say",
            type: "POST",
            dataType: "json",
            data: data,
            success: function (res) {
                console.log(res);
                if (res.code === 200) {
                    let data = JSON.parse(res.data);
                    console.log(data);
                    var time = "发表时间：" + YY + "年" + MM + "月" + DD + "号" + hh + "时" + mm + "分" + ss + "秒";
                    let html = time + `
                        <div class="card border-primary shadow" style="width: 50rem;">
                            <div class="card-header">
                                <div class="row">
                                    <div class="col-sm-10">${data.content}</div>
                                    <div class="col-sm-2"><button type="button" class="btn btn-secondary btn-sm"
                                            data-toggle="modal" data-target="#comment"
                                            onclick="msgCommit(${data.id})" style="background-color:deepskyblue">Talk Show</button>
                                    </div>
                                </div>

                            </div>
                            <div class="card-body">
                                <ul class="list-group list-group-flush" id="${data.id}">
                                   
                                </ul>

                            </div>
                        </div>
                        `;
                    $("#saysayMsg").prepend(html);
                    window.location.href = '/'
                    // window.location.href="/login";
                }
            },
            error: function (msg) {
                console.log('网络或者服务器有问题');
            }
        })
    }

    function msgCommit(msgId) {
        currentMsgId = msgId;
    }

    function talkComment() {
        var getTime = new Date();
        var YY = getTime.getFullYear();
        var MM = getTime.getMonth() + 1;
        var DD = getTime.getDate();
        var hh = getTime.getHours();
        var mm = getTime.getMinutes();
        var ss = getTime.getSeconds();
        var day = getTime.getDay();

        let data = {
            msgId: currentMsgId,
            content: $('#commentText').val()
        }
        $.ajax({
            url: "/comment",
            type: "POST",
            dataType: "json",
            data: data,
            success: function (res) {
                console.log(res);
                if (res.code === 200) {
                    var time = "吐槽时间：" + YY + "年" + MM + "月" + DD + "号" + hh + "时" + mm + "分" + ss + "秒";
                    let html = `
                            <li class="list-group-item">
                                <blockquote class="blockquote mb-0">
                                    <p>${data.content}</p>
                                    <footer class="blockquote-footer">
                                        <cite title="Source Title">${data.fromUserName}</cite>&nbsp;&nbsp;对
                                        <cite title="Source Title">${data.toUserName}</cite>&nbsp;&nbsp;说
                                    </footer>
                                </blockquote>
                            </li>
                        ` + time;
                    $("#" + currentMsgId).append(html);

                    window.location.href = '/'
                }
            },
            error: function (msg) {
                console.log('网络或者服务器有问题');
            }
        });
    }


    //分页
    $(function () {

        goPage(1, 10);
        var tempOption = "";
        for (var i = 1; i <= totalPage; i++) {
            tempOption += '<option value=' + i + '>' + i + '</option>'
        }
        $("#jumpWhere").html(tempOption);
    })


    var pageSize = 0; //每页显示行数
    var currentPage_ = 1; //当前页全局变量，用于跳转时判断是否在相同页，在就不跳，否则跳转。
    var totalPage; //总页数
    function goPage(pno, psize) {
        var itable = document.getElementById("adminTbody");
        var num = itable.rows.length; //表格所有行数(所有记录数)

        pageSize = psize; //每页显示行数
        //总共分几页 
        if (num / pageSize > parseInt(num / pageSize)) {
            totalPage = parseInt(num / pageSize) + 1;
        } else {
            totalPage = parseInt(num / pageSize);
        }
        var currentPage = pno; //当前页数
        currentPage_ = currentPage;
        var startRow = (currentPage - 1) * pageSize + 1;
        var endRow = currentPage * pageSize;
        endRow = (endRow > num) ? num : endRow;
        //遍历显示数据实现分页
        for (var i = 1; i < (num + 1); i++) {
            var irow = itable.rows[i - 1];
            if (i >= startRow && i <= endRow) {
                irow.style.display = "";
            } else {
                irow.style.display = "none";
            }
        }

        $("#adminTbody tr").hide();
        for (var i = startRow - 1; i < endRow; i++) {
            $("#adminTbody tr").eq(i).show();
        }
        var tempStr = "共" + num + "条记录 分" + totalPage + "页 当前第" + currentPage + "页";
        document.getElementById("barcon1").innerHTML = tempStr;

        if (currentPage > 1) {
            $("#firstPage").on("click", function () {
                goPage(1, psize);
            }).removeClass("ban");
            $("#prePage").on("click", function () {
                goPage(currentPage - 1, psize);
            }).removeClass("ban");
        } else {
            $("#firstPage").off("click").addClass("ban");
            $("#prePage").off("click").addClass("ban");
        }

        if (currentPage < totalPage) {
            $("#nextPage").on("click", function () {
                goPage(currentPage + 1, psize);
            }).removeClass("ban")
            $("#lastPage").on("click", function () {
                goPage(totalPage, psize);
            }).removeClass("ban")
        } else {
            $("#nextPage").off("click").addClass("ban");
            $("#lastPage").off("click").addClass("ban");
        }

        $("#jumpWhere").val(currentPage);
    }


    function jumpPage() {
        var num = parseInt($("#jumpWhere").val());
        if (num != currentPage_) {
            goPage(num, pageSize);
        }
    }
</script>



</html>